<template>
	<view>
		<scroll-view class="scroll-view" scroll-y="true" @scroll="scroll" @scrolltolower="lower" :style="'height:'+scriptHeight+'px'">
		<view class="poet" v-if="poet != ''">
			<view class="first">
				<view class="avatar"><image :src="poet.avatar"></image></view>
				<view class="other">
					<view class="name">{{poet.name}}<text v-if="poet.alias != ''">({{poet.alias}})</text></view>
					<viw class="dynasty">年代：{{poet.dynasty}}</viw>
					<view class="dynasty">收录：{{poet.poetry_count}}</view>
				</view>
				<view class="zuhe" v-if="poet.designation != ''">
					<view v-for="(item,index) in poet.designation" :key="index">
						<view class="item">{{item}}之一</view>
					</view>
				</view>
			</view>
			<view class="content">{{poetDesc}}<view class="look-desc-action" @click="lookAll">{{lookDescAction}}</view></view>
		</view>
		<view class="third" v-for="(item,index) in poetry" :key="index" @click="toUrl(item.id)">
			<view class="item">
				<view class="title">{{item.title}}</view>
				<view class="item-text">{{item.content}}</view>
				<view class="item-button">
					<!-- <view class="left">{{item.title}}</view> -->
					<view class="right">{{item.hit}} 人浏览</view>
				</view>
			</view>
		</view>
		</scroll-view>
	</view>
</template>

<script>
	import unils from "../../unils/utils.js"
	export default {
		data() {
			return {
				'scriptHeight':400,
				'poetry':[],
				'dynastyId':0,//朝代id
				'poetId':0,//诗人id
				'labelId':0,//标签id
				'currentPage':1,//当前页数
				'flag':true,
				'poet':[],
				'poetDesc':'',
				'lookDescAction':'展开',
			}
		},
		onReady() {
			this.scriptHeight = uni.getSystemInfoSync().windowHeight;
		},
		onLoad(option) {
			this.dynastyId = option.dynasty_id;
			this.poetId = option.poet_id;
			this.labelId = option.label_id;
			if(this.dynastyId == undefined){
				this.dynastyId = 0;
			}
			if(this.poetId == undefined){
				this.poetId = 0;
			}
			if(this.labelId == undefined){
				this.labelId = 0;
			}
			// this.poetId = 191;
			console.log(this.poetId);
			console.log(this.dynastyId);
			console.log(this.labelId);
			this.getData();
		},
		methods: {
			lookAll:function(){
					if(this.lookDescAction == "展开"){
						this.poetDesc = this.poet.descr;
						this.lookDescAction = "收起";
					} else {
						this.poetDesc = this.poet.descr.substring(0,50);
						this.lookDescAction = "展开";
					}
					
			},
			lower:function(){
				// console.log('scrolltolower');
				if(this.flag){
					this.getData();
				}
			},
			scroll:function(e){
				// console.log('lower');
			},
			toUrl:function(id){
				uni.navigateTo({
					url:"../article_sc/article_sc?id="+id
				})
			},
			getData:function(){
				let that = this;
				that.flag = false;
				uni.request({
					url: that.websiteUrl+'/listpoetry',
					method:'GET',
					header: {
					        'x-requested-with': 'xmlhttprequest' //自定义请求头信息
					    },
					data:{
						'dynasty_id':that.dynastyId,
						'poet_id':that.poetId,
						'label_id':that.labelId,
						'c_page':that.currentPage,
					},
					success:(res)=>{
						if(res.data.code != 1){
							uni.showToast({
								title:res.data.msg,
								duration:2000,
								icon:'none',
							})
						} else {
							that.poetry = that.poetry.concat(res.data.data.poetry);
							that.poet = res.data.data.poet;
							if(!unils.stringIsEmpty(res.data.data.poet.descr)){
								that.poetDesc = res.data.data.poet.descr.substring(0,50);
							}
							
							that.currentPage++;
							console.log(res.data.data);
						}
						that.flag = true;
					}
				})
			}
		}
	}
</script>

<style lang="scss">
.scroll-view{
	height: 450px;
	background-color: $uni-scroll-bg-clolr;
	.third{
		
		.item{
			font-size: $uni-list-content-font-size;
			margin: 15px 10px;
			background-color: #FFFFFF;
			padding:15px 15px;
			border-radius: 3px;
			color:$uni-text-color;
			.title{
				font-size: $uni-list-content-font-size;
				font-weight: bold;
				display: flex;
				justify-content: center;
				align-items: center;
				width: 100%;
				padding-bottom: 10px;
				color:$uni-text-color;
			}
			.item-text{
				
			}
			.item-button{
				font-size:11px;
				display: flex;
				// justify-content: flex-end;
				margin-top: 10px;
				.left{
					font-size: 14px;
					font-weight: bold;
					// display: flex;
					// justify-content: flex-start;
					width: 100%;
					color:$uni-text-color;
				}
				.right{
					flex-shrink: 0;
					
					color:$uni-primary-color;
					display: flex;
					justify-content: flex-end;
					padding-right: 3px;
				}
			}
		}
	}
	//诗人
	.poet{
		margin: 10px;
		background-color: $uni-bg-color;
		border-radius: 5px;
		padding: 10px;
		display: flex;
		flex-direction: column;
		// justify-content: center;
		.first{
			display: flex;
			font-size: 15px;
			.avatar{
				margin-right: 10px;
				image{
					width:70px;
					height:70px;
					border-radius: 10px;
				}
			}
			.other{
				color:$uni-text-color;
				// display: flex;
				// justify-content: space-around;
				// flex-direction: column;
				margin-left: 5px;
				.name{
					font-size:16px;
					font-weight: bold;
				}
				.dynasty{
					font-size:14px;
					// font-weight: bold;
				}
				
			}
			.zuhe{
				display: flex;
				// flex-direction: column;
				margin-left: 15px;
				.item{
					display: flex;
					margin: 5px;
					font-size: 13px;
					// height:30px;
					padding: 5px;
					border-radius: 5px;
					
					background-color: $uni-primary-color;
					color: $uni-bg-color;
				}
				
			}
		}
		.content{
			color:$uni-text-color;
			margin-top: 10px;
			font-size: 13px;
			line-height: 20px;
			.look-desc-action{
				display: flex;
				justify-content: center;
				margin-top: 10px;
			}
		}
	}
}
</style>
